
import { request } from '../request'

// 全局请求拦截器
request.setInterceptor(
  (config) => {
    // 自动添加token
    config.header = {
      ...config.header,
      Authorization: uni.getStorageSync('token')
    }
    return config
  },
  (response) => {
    //统一处理响应数据结构
    if (response.data.code < 200 && response.data.code >= 300) {
      return Promise.reject(response.data)
    }
    return response.data
  }
)

// 用户模块接口
export const userAPI = {
  userInfo: (data,header) => request.get('user/info/'+data.id, [],header),
  companyInfo: (data,header) => request.get('company/info', [],header),
  // 获取coze授权token
  getCozeAccessToken: (data) => request.get('coze/auth', data)
}

// 订单模块接口
export const orderAPI = {
  create: (data) => request.post('/api/orders', data),
  list: (params) => request.get('/api/orders', { params })
}

// 商品模块接口
export const productAPI = {
  getDetail: (id) => request.get(`/api/products/${id}`),
  search: (keywords) => request.get('/api/products/search', { params: { keywords } })
}